package com.lijiajian.controller;

import com.lijiajian.Service.CustomerService;
import com.lijiajian.base.BaseController;
import com.lijiajian.base.ResultInfo;
import com.lijiajian.pojo.Customer;
import com.lijiajian.query.CustomerQuery;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("customer")
public class CustomerController extends BaseController {
    @Resource
    private CustomerService customerService;

    /**
     * 多条件查询客户信息
     * @param customerQuery
     * @return
     */
    @GetMapping("list")
    @ResponseBody
    public Map<String,Object> queryCustomerByParams(CustomerQuery customerQuery){
       return customerService.queryCustomerByParams(customerQuery);
    }

    /**
     * 前往客户信息页面
     * @return
     */
    @GetMapping("index")
    public String toCustomer(){
        return "customer/customer";
    }

    @GetMapping("getLevels")
    @ResponseBody
    public List<String> getlevels(){
        List<String> levelList=new ArrayList<>();
        levelList.add("大客户");
        levelList.add("战略合作伙伴");
        levelList.add("重点开发客户");
        return levelList;
    }

    /**
     * 添加页面
     * @param customer
     * @return
     */
    @PostMapping("add")
    @ResponseBody
    public ResultInfo addCustomer(Customer customer){
        customerService.addCustomer(customer);
        return success("添加客户成功");
    }


    /**
     * 添加页面
     * @param customer
     * @return
     */
    @PostMapping("update")
    @ResponseBody
    public ResultInfo updateCustomer(Customer customer){
        customerService.updateCustomer(customer);
        return success("修改客户成功");
    }

    @PostMapping("delete")
    @ResponseBody
    public ResultInfo deleteCustomer(Integer[] ids){
        customerService.deleteCustomer(ids);
        return success("删除客户成功");
    }

    /**
     * 前往添加或修改页面
     * @return
     */
    @GetMapping("toAddAndUpdatePage")
    public String toAddAndUpdatePage(Integer id, HttpServletRequest request){
        if(id!=null){
            request.setAttribute("customer",customerService.selectByPrimaryKey(id));
        }
        return "customer/addAndUpdate";
    }
    /**
     * 打开订单页面
     */
    @GetMapping("toCustomerOrderPage")
    public String toCustomerOrderPage(Integer customerId,HttpServletRequest request){
        if(null!=customerId){
            request.setAttribute("customer",customerService.selectByPrimaryKey(customerId));
        }
        return "customerOrder/customerOrder";
    }



}
